from ..extensions import db
from .base import BaseModel

class Airport(BaseModel):
    """机场信息模型"""
    __tablename__ = 'Airports'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    region = db.Column(db.String(50))
    latitude = db.Column(db.Float)
    longitude = db.Column(db.Float)
    hangar_capacity = db.Column(db.Float, nullable=False)
    shelter_capacity = db.Column(db.Float, nullable=False)
    mask_capacity = db.Column(db.Float, nullable=False)
    cave_capacity = db.Column(db.Float, nullable=False)
    mask_count = db.Column(db.Float, nullable=False)
    total_capacity = db.Column(db.Float, nullable=False)
    aircraft_count = db.Column(db.Float, nullable=False)
    parking_apron_count = db.Column(db.Float, nullable=False)
    w_field = db.Column(db.Float, nullable=False)
    l_field = db.Column(db.Float, nullable=False)
    i_field = db.Column(db.Float, nullable=False)
    t_field = db.Column(db.Float, nullable=False)
    p_field = db.Column(db.Float, nullable=False)
    c_field = db.Column(db.Float, nullable=False)
    
    # 关系
    runways = db.relationship('Runway', backref='airport', lazy=True)
    parking_aprons = db.relationship('ParkingApron', backref='airport', lazy=True)
    oil_tanks = db.relationship('OilTank', backref='airport', lazy=True)
    ammunition_depots = db.relationship('AmmunitionDepot', backref='airport', lazy=True)
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'region': self.region,
            'latitude': self.latitude,
            'longitude': self.longitude,
            'hangar_capacity': self.hangar_capacity,
            'shelter_capacity': self.shelter_capacity,
            'mask_capacity': self.mask_capacity,
            'cave_capacity': self.cave_capacity,
            'mask_count': self.mask_count, 
            'total_capacity': self.total_capacity,
            'aircraft_count': self.aircraft_count,
            'parking_apron_count': self.parking_apron_count,
            'w_field': self.w_field,
            'l_field': self.l_field,
            'i_field': self.i_field,
            't_field': self.t_field,
            'p_field': self.p_field,
            'c_field': self.c_field,
            'created_at': self.created_at.isoformat(),
            'updated_at': self.updated_at.isoformat()
        } 